<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('模板列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<style>
    select {
        padding-top: 3px !important;
    }

    .select-list {
        margin-top: 5px !important;
    }

    .select-list li p {
        width: auto !important;
        margin-top: 7px !important;
    }

    .form-header {
        margin: 10px auto !important;

    }


</style>
<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="project-form">
                    <div class="col-sm-12">
                        <div class="select-list">
                            <ul>
                                <li>
                                    二级部门：<select class="form-control" name="deptId" id="deptId">
                                    <option value="">请选择</option>
                                    <option th:each="dep:${secondaryDeptList}" th:value="${dep.deptId }"
                                            th:text="${dep.deptName }"></option>
                                </select>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                            class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                            class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-warning" onclick="downLoadTemplate()">
                        <i class="fa fa-download"></i> 下载绩效模板
                    </a>
                    <a class="btn btn-info" onclick="importExcel()">
                        <i class="fa fa-upload"></i> 导入所有岗位绩效指标
                    </a>
                </div>
                <table id="bootstrap-table"></table>
            </div>

        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">
    var prefix = ctx + "acvTpManage"
    $(function () {

        var options = {
            url: prefix + '/findTwoDept',
            uniqueId: "id",
            id: 'bootstrap-table',
            importUrl: prefix + "/importTemplateFile",
            modalName: "部门岗位",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: true,
            detailView: true,
            detailFormatter: function (index, row, $detail) {
                initChildTable(index, row, $detail);
            },
            columns: [
                {
                    field: 'deptName',
                    title: '二级部门名称'
                },
                {
                    title: '类型',
                    formatter: function (value, item, index) {
                        return '<span class="label label-success">二级部门</span>';
                    }
                }
            ]
        }
        $.table.init(options);
    });

    initChildTable = function (index, row, $detail) {
        var childTable = $detail.html('<table></table>').find('table');
        $(childTable).bootstrapTable({
            url: prefix + "/findThreeDept",
            queryParams: {parentId: row.deptId},
            method: 'post',
            uniqueId: row.id,
            sidePagination: "server",
            contentType: "application/x-www-form-urlencoded",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: false,
            detailView: true,
            detailFormatter: function (index, row, $detail) {
                initChildTable1(index, row, $detail);
            },
            columns: [
                {
                    field: 'deptName',
                    title: '三级部门名称'
                },
                {
                    title: '类型',
                    formatter: function (value, item, index) {
                        return '<span class="label label-primary">三级部门</span>';
                    }
                }
            ]
        });
    }


    initChildTable1 = function (index, row, $detail) {
        var childTable = $detail.html('<table></table>').find('table');
        $(childTable).bootstrapTable({
            url: prefix + "/findJobByDeptId",
            queryParams: {deptId: row.deptId},
            method: 'post',
            uniqueId: row.id,
            sidePagination: "server",
            contentType: "application/x-www-form-urlencoded",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: false,
            detailView: true,
            detailFormatter: function (index, row, $detail) {
                initChildTable2(index, row, $detail);
            },
            columns: [
                {
                    field: 'jobName',
                    title: '岗位名称'
                },
                {
                    title: '类型',
                    formatter: function (value, item, index) {
                        return '<span class="label label-warning">岗位</span>';
                    }
                },
                {
                    title: '操作',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + '" onclick="uploadTemplateData(\'' + row.jobId + '\')" href="javascript:void(0)"><i class="fa fa-plus"></i>上传</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + '" onclick="downloadTemplateByJobId(\'' + row.jobId + '\')" href="javascript:void(0)"><i class="fa fa-download"></i>下载</a> ');
                        return actions.join('');
                    }
                }
            ]
        });
    }

    initChildTable2 = function (index, row, $detail) {
        var childTable = $detail.html('<table></table>').find('table');
        $(childTable).bootstrapTable({
            url: prefix + "/findTemplateDataByJobId",
            queryParams: {jobId: row.jobId},
            method: 'post',
            uniqueId: row.id,
            sidePagination: "server",
            contentType: "application/x-www-form-urlencoded",
            columns: [
                {
                    field: 'assessment_index',
                    title: '考核指标'
                },
                {
                    field: 'describe',
                    title: '指标描述/计算公式'
                },
                {
                    field: 'goal',
                    title: '达成目标'
                },
                {
                    field: 'standard',
                    title: '评分标准'
                },
                {
                    field: 'distribution',
                    title: '指标配分'
                },
                {
                    title: '类型',
                    formatter: function (value, item, index) {
                        return '<span class="label label-primary">考核数据</span>';
                    }
                }
            ]
        });
    }

    function downLoadTemplate() {
        $.operate.exportData("acvTemplateManage/downloadTemplate", "考核项模板");
    }

    function importExcel() {
        $.modal.confirm("导入会覆盖所有原来的数据,确定导入吗?", function () {
            $.table.importExcel();
        });
    }

    function uploadTemplateData(jobId) {
        $.table.importExcelCustom("uploadTpl", "上传考核数据", prefix + "/uploadTemplateData?jobId=" + jobId, 'file1');
    }

    function downloadTemplateByJobId(jobId) {
        $.operate.exportData("acvTpManage/downloadTemplateByJobId?jobId=" + jobId, "岗位考核项数据");
    }
</script>
</body>

<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>

<script id="uploadTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file1" name="file"/>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>

</html>